<template>
    <div>
        <div>
            <el-form :inline="true" :model="serchData" class="demo-form-inline">
                <el-form-item label="考核类型">
                    <el-select v-model="serchData.assessmentType" placeholder="请选择" style="width: 120px;" clearable>
                        <el-option label="月度考核" value="月度考核" />
                    </el-select>
                </el-form-item>
                <el-form-item label="方案名称">
                    <el-input v-model="serchData.schemeName" placeholder="请输入" clearable style="width: 200px;" />
                </el-form-item>
                <el-form-item>
                    <el-button type="success" @click="getAssessmentSchemeList">搜索</el-button>
                </el-form-item>
            </el-form>

            <el-button type="success" @click="dialogVisible = true, resetForm(ruleFormRef)">新增</el-button>
            <el-button type="success" @click="dialogVisible5 = true">查看解决方案</el-button>
            <el-table border :data="assessmentSchemeList" style="width: 100%">
                <el-table-column type="index" label="序号" width="60" align="center" :index="indexMethod" />
                <el-table-column prop="schemeName" label="方案名称" align="center" />
                <el-table-column prop="assessmentType" label="考核类型" align="center" />
                <el-table-column prop="assessmentObject" label="考核对象" align="center" />
                <el-table-column prop="assessmentState" label="状态" align="center" />
                <el-table-column label="操作" width="225">
                    <template v-slot="scope">
                        <el-link type="primary" size="small" @click="editAssessmentScheme(scope.row.id)">编辑</el-link>
                        &ensp;
                        <el-link type="danger" size="small" @click="deleteAssessmentScheme(scope.row.id)">删除</el-link>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <!-- 分页 -->
        <table style="margin: 5px auto;">
            <tbody>
                <tr>
                    <td>
                        <el-pagination v-model:current-page="page.pageIndex" v-model:page-size="page.pageSize"
                            :page-sizes="[15, 20, 25, 30]" background layout="slot" :total="page.totalCount"
                            @size-change="handleSizeChange" @current-change="handleCurrentChange" prev-text="上一页"
                            next-text="下一页">
                            <span>
                                共 {{ page.totalCount }} 条，共 {{ page.pageCount }} 页，当前 {{ page.pageIndex }} / {{
                                    page.pageCount
                                }} 页
                            </span>
                        </el-pagination>
                    </td>
                    <td>
                        <el-pagination v-model:current-page="page.pageIndex" v-model:page-size="page.pageSize"
                            :page-sizes="[15, 20, 25, 30]" background layout="sizes, slot,prev, pager, next"
                            :total="page.totalCount" @size-change="handleSizeChange"
                            @current-change="handleCurrentChange" prev-text="上一页" next-text="下一页">
                            <span>
                                <button @click="handleCurrentChange(1)" :disabled="page.pageIndex == 1">首页</button>
                            </span>
                        </el-pagination>
                    </td>
                    <td>
                        <el-pagination v-model:current-page="page.pageIndex" v-model:page-size="page.pageSize"
                            :page-sizes="[15, 20, 25, 30]" background layout="slot,jumper" :total="page.totalCount"
                            @size-change="handleSizeChange" @current-change="handleCurrentChange" prev-text="上一页"
                            next-text="下一页">
                            <span>
                                <button @click="handleCurrentChange(page.pageCount)"
                                    :disabled="page.pageIndex == page.pageCount">尾页</button>
                            </span>
                        </el-pagination>
                    </td>
                </tr>
            </tbody>
        </table>

        <!-- 方案弹出框 -->
        <el-dialog v-model="dialogVisible" title="新增考核方案" width="30%">
            <el-form ref="ruleFormRef" style="max-width: 600px" :model="ruleForm" :rules="rules" label-width="auto"
                class="demo-ruleForm" status-icon>
                <el-form-item label="方案名称:" prop="schemeName">
                    <el-input v-model="ruleForm.schemeName" style="width: 220px;" />
                </el-form-item>
                <el-form-item label="考核类型:" prop="assessmentType">
                    <el-select v-model="ruleForm.assessmentType" style="width: 220px;" clearable>
                        <el-option label="月度考核" value="月度考核" />
                    </el-select>
                </el-form-item>
                <el-form-item label="考核周期:" prop="assessmentCycle">
                    <el-date-picker v-model="ruleForm.assessmentCycle" type="month" value-format="YYYY/MM" />
                </el-form-item>
                <el-form-item label="考核对象:" prop="assessmentObject">
                    <el-row :gutter="20">
                        <el-col :span="20" :offset="0">
                            <el-input v-model="ruleForm.assessmentObject" type="textarea"
                                :autosize="{ minRows: 7, maxRows: 7 }" disabled />
                        </el-col>
                        <el-col :span="4" :offset="0">
                            <el-tag @click="Select">选择</el-tag>
                            <br />
                            <br />
                            <el-tag @click="deldata">删除</el-tag>
                        </el-col>
                    </el-row>
                </el-form-item>
                <el-form-item label="评价方式:">
                    <div>
                        <el-checkbox>
                            <el-form-item label="客观评价:" prop="objectiveEvaluationWeight">
                                <el-tag @click="SelectObjective">选择指标</el-tag>&nbsp;&nbsp;&nbsp;权重:<el-input
                                    v-model="ruleForm.objectiveEvaluationWeight" style="width: 80px;" />
                            </el-form-item>
                        </el-checkbox>
                        <br /><br />
                        <el-checkbox>
                            <el-form-item label="主观评价:" prop="subjectiveEvaluationWeight">
                                <el-tag @click="Selectsubjective">选择指标</el-tag>&nbsp;&nbsp;&nbsp;权重:<el-input
                                    v-model="ruleForm.subjectiveEvaluationWeight" style="width: 80px;" />
                            </el-form-item>
                        </el-checkbox>
                    </div>
                </el-form-item>
                <el-form-item>
                    <el-button @click="resetForm(ruleFormRef)">取消</el-button>
                    <el-button style="background-color:cornflowerblue; color: white"
                        @click="submitForm(ruleFormRef, 1)">保存</el-button>
                    <el-button type="primary" @click="submitForm(ruleFormRef, 2)">
                        提交
                    </el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <el-dialog v-model="dialogVisible6" title="新增考核方案" width="30%">
            <el-form ref="ruleFormRef" style="max-width: 600px" :model="ruleForm" :rules="rules" label-width="auto"
                class="demo-ruleForm" status-icon>
                <el-form-item label="方案名称:" prop="schemeName">
                    <el-input v-model="ruleForm.schemeName" style="width: 220px;" />
                </el-form-item>
                <el-form-item label="考核类型:" prop="assessmentType">
                    <el-select v-model="ruleForm.assessmentType" style="width: 220px;" clearable>
                        <el-option label="月度考核" value="月度考核" />
                    </el-select>
                </el-form-item>
                <el-form-item label="考核周期:" prop="assessmentCycle">
                    <el-date-picker v-model="ruleForm.assessmentCycle" type="month" value-format="YYYY/MM" />
                </el-form-item>
                <el-form-item label="考核对象:" prop="assessmentObject">
                    <el-row :gutter="20">
                        <el-col :span="20" :offset="0">
                            <el-input v-model="ruleForm.assessmentObject" type="textarea"
                                :autosize="{ minRows: 7, maxRows: 7 }" disabled />
                        </el-col>
                        <el-col :span="4" :offset="0">
                            <el-tag @click="Select">选择</el-tag>
                            <br />
                            <br />
                            <el-tag @click="deldata">删除</el-tag>
                        </el-col>
                    </el-row>
                </el-form-item>
                <el-form-item label="评价方式:">
                    <div>
                        <el-checkbox>
                            <el-form-item label="客观评价:" prop="objectiveEvaluationWeight">
                                <el-tag>选择指标</el-tag>&nbsp;&nbsp;&nbsp;权重:<el-input
                                    v-model="ruleForm.objectiveEvaluationWeight" style="width: 80px;" />
                            </el-form-item>
                        </el-checkbox>
                        <br /><br />
                        <el-checkbox>
                            <el-form-item label="主观评价:" prop="subjectiveEvaluationWeight">
                                <el-tag>选择指标</el-tag>&nbsp;&nbsp;&nbsp;权重:<el-input
                                    v-model="ruleForm.subjectiveEvaluationWeight" style="width: 80px;" />
                            </el-form-item>
                        </el-checkbox>
                    </div>
                </el-form-item>
                <el-form-item>
                    <el-button @click="resetForm(ruleFormRef)">取消</el-button>
                    <el-button type="primary" @click="update">
                        修改
                    </el-button>
                </el-form-item>
            </el-form>
        </el-dialog>
        <!-- 考核对象弹出框 -->
        <el-dialog v-model="dialogVisible2" title="选择考核对象" width="45%">
            <el-row :gutter="20">
                <el-col :span="12" :offset="0">
                    <h4>选择考核网络</h4>
                    <el-tree style="max-width: 600px" :data="data" default-expand-all node-key="id" highlight-current
                        :props="defaultProps" getCheckedKeys :expand-on-click-node="false"
                        @node-click="handleNodeClick" />
                </el-col>
                <el-col :span="12" :offset="0">
                    <h4>选择考核对象</h4>
                    <p v-for="id in selectedNodeIds" :key="id">{{ id }}</p>
                </el-col>
            </el-row>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="dialogVisible2 = false">取消</el-button>
                    <el-button type="primary" @click="dialogVisible2 = false">
                        提交
                    </el-button>
                </span>
            </template>
        </el-dialog>
        <!-- 客观考核指标弹出框 -->
        <el-dialog v-model="dialogVisible3" title="选择客观考核指标" width="45%">
            <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" />
                <el-table-column prop="indexName" label="指标名称" align="center" />
                <el-table-column prop="indexDesc" label="指标描述" align="center" />
                <el-table-column prop="maximumFraction" label="最大分" align="center" />
                <el-table-column prop="leastMinute" label="最小分" align="center" />
            </el-table>
            <table style="width: 100%">
                <tbody>
                    <tr>
                        <td>评分规则</td>
                        <td>指标权重</td>
                    </tr>
                    <tr>
                        <td>
                            <div>
                                <el-input v-model="scoringRuleData.percent1" style="width: 40px;" />%
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <el-input v-model="scoringRuleData.Points1" style="width: 40px;" />分
                                <br />
                                <el-input v-model="scoringRuleData.percent2" style="width: 40px;" />%-
                                <el-input v-model="scoringRuleData.percent3" style="width: 40px;" />%
                                <el-input v-model="scoringRuleData.Points2" style="width: 40px;" />分
                                <br />
                                <el-input v-model="scoringRuleData.percent4" style="width: 40px;" />%-
                                <el-input v-model="scoringRuleData.percent5" style="width: 40px;" />%
                                <el-input v-model="scoringRuleData.Points3" style="width: 40px;" />分
                                <br />
                                <el-input v-model="scoringRuleData.percent6" style="width: 40px;" />%-
                                <el-input v-model="scoringRuleData.percent7" style="width: 40px;" />%
                                <el-input v-model="scoringRuleData.Points4" style="width: 40px;" />分
                                <br />
                                <el-input v-model="scoringRuleData.percent8" style="width: 40px;" />%
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <el-input v-model="scoringRuleData.Points5" style="width: 40px;" />分
                            </div>
                        </td>
                        <td>
                            <el-input v-model="scoringRuleData.indexWeight" style="width: 80px;" disabled />
                        </td>
                    </tr>
                </tbody>
            </table>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="dialogVisible3 = false">取消</el-button>
                    <el-button type="primary" @click="saveScoringRule">
                        提交
                    </el-button>
                </span>
            </template>
        </el-dialog>
        <!-- 主观考核指标弹出框 -->
        <el-dialog v-model="dialogVisible4" title="选择主观考核指标" width="45%">
            <el-row :gutter="20">
                <el-col :span="20" :offset="0">
                    <el-table :data="tableData1" border style="width: 100%" @selection-change="handleSelectionChange1">
                        <el-table-column type="selection" width="55" />
                        <el-table-column prop="indexName" label="指标名称" align="center" />
                        <el-table-column prop="indexDesc" label="指标描述" align="center" />
                        <el-table-column prop="maximumFraction" label="最大分" align="center" />
                        <el-table-column prop="leastMinute" label="最小分" align="center" />
                        <el-table-column prop="initialScore" label="初始分" align="center" />
                    </el-table>
                </el-col>
                <el-col :span="4" :offset="0">
                    <table>
                        <tr>
                            <td>指标权重</td>
                        </tr>
                        <br />
                        <br />
                        <tr>
                            <td>
                                <div v-for="(item, index) in selecttableData1" :key="index">
                                    <el-input v-model="item.indexWeight" style="width: 80px;" :disabled="true" />
                                </div>
                            </td>
                        </tr>
                    </table>
                </el-col>
            </el-row>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="dialogVisible4 = false">取消</el-button>
                    <el-button type="primary" @click="saveSubjective">
                        提交
                    </el-button>
                </span>
            </template>
        </el-dialog>
        <!-- 查看解决方案弹出框 -->
        <el-dialog v-model="dialogVisible5" title="我的考核方案" width="70%">
            <el-row :gutter="20">
                <el-col :span="8" :offset="0">
                    <el-card class="box-card"
                        style="background-color:white;border: 1px solid black;height: 500px;width: 300px;">
                        <p>月度考评</p>
                        <br />
                        <el-select v-model="schemeName" placeholder="请选择" size="small" style="width: 140px"
                            @change="getMySolution">
                            <el-option v-for="item in schemeNameList" :label="item.schemeName" :value="item.id" />
                        </el-select>
                    </el-card>
                </el-col>
                <el-col :span="16" :offset="0">
                    <el-card class="box-card"
                        style="background-color:white;border: 1px solid black;height: 130px;width: 500px;">
                        <table>
                            <tr>
                                <td>方案名称:&nbsp;&nbsp;&nbsp;&nbsp;{{ assessmentScheme.schemeName }}</td>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <td>考核类型:&nbsp;&nbsp;&nbsp;&nbsp;{{ assessmentScheme.assessmentType }}</td>
                            </tr>
                            <br />
                            <tr>
                                <td>考核周期:&nbsp;&nbsp;&nbsp;&nbsp;{{ assessmentScheme.assessmentCycle.substring(0, 7) }}
                                </td>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <td>评价方式:&nbsp;&nbsp;&nbsp;&nbsp;
                                    主观评价 权重{{ assessmentScheme.subjectiveEvaluationWeight }}
                                    <br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    客观评价 权重{{ assessmentScheme.objectiveEvaluationWeight }}
                                </td>
                            </tr>
                        </table>
                    </el-card>
                    <br />
                    <br />
                    <el-tabs type="card" class="demo-tabs">
                        <el-tab-pane label="主观指标">
                            <el-table :data="SchemeAssessmentIndexTable" border style="width: 100%">
                                <el-table-column prop="indexName" label="指标名称" align="center" />
                                <el-table-column prop="indexDesc" label="指标描述" align="center" />
                                <el-table-column prop="maximumFraction" label="最大分" align="center" />
                                <el-table-column prop="leastMinute" label="最小分" align="center" />
                                <el-table-column prop="initialScore" label="初始分" align="center" />
                                <el-table-column prop="indexWeight" label="评分权重" align="center" />
                            </el-table>
                        </el-tab-pane>
                        <el-tab-pane label="客观指标">
                            <el-table :data="ObjectiveAssessmentTable" border style="width: 100%">
                                <el-table-column prop="indexName" label="指标名称" align="center" />
                                <el-table-column prop="indexDesc" label="指标描述" align="center" />
                                <el-table-column prop="maximumFraction" label="最大分" align="center" />
                                <el-table-column prop="leastMinute" label="最小分" align="center" />
                                <el-table-column label="评分规则" align="center">
                                    <div>
                                        <p>{{ scoringRule.percent1 }}%&nbsp;&nbsp;{{ scoringRule.points1 }}分</p>
                                        <p>{{ scoringRule.percent2 }}%&nbsp;-&nbsp;{{ scoringRule.percent3
                                            }}%&nbsp;&nbsp;{{
                                                scoringRule.points2 }}分
                                        </p>
                                        <p>{{ scoringRule.percent4 }}%&nbsp;-&nbsp;{{ scoringRule.percent5
                                            }}%&nbsp;&nbsp;{{
                                                scoringRule.points3 }}分
                                        </p>
                                        <p>{{ scoringRule.percent6 }}%&nbsp;-&nbsp;{{ scoringRule.percent7
                                            }}%&nbsp;&nbsp;{{
                                                scoringRule.points4 }}分
                                        </p>
                                        <p>{{ scoringRule.percent8 }}%&nbsp;&nbsp;{{ scoringRule.points5 }}分</p>
                                    </div>
                                </el-table-column>
                                <el-table-column label="指标权重" align="center">
                                    {{ scoringRule.indexWeight }}
                                </el-table-column>
                            </el-table>
                        </el-tab-pane>
                    </el-tabs>
                </el-col>
            </el-row>

            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="dialogVisible5 = false">确定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, inject } from 'vue'
import { ElMessage, ElMessageBox, ElTree, type FormInstance, type FormRules } from 'element-plus'
import type { AxiosStatic } from "axios"
import { useRouter } from 'vue-router'
const axios = inject('axios') as AxiosStatic
const ruleFormRef = ref<FormInstance>()
const router = useRouter()

//方案弹出层变量
const dialogVisible = ref(false)
//考核对象弹出层变量
const dialogVisible2 = ref(false)
//客观指标弹出层变量
const dialogVisible3 = ref(false)
//主观指标弹出层变量
const dialogVisible4 = ref(false)
//查看解决方案弹出层变量
const dialogVisible5 = ref(false)
const dialogVisible6 = ref(false)

const Id = ref(0)


//回显考核方案
const editAssessmentScheme = (id: number) => {
    dialogVisible6.value = true
    axios.get('http://47.95.178.186:8000/ExamineGetRout/api/AssessmentSchemeRead/GetAssessmentSchemeInfo', {
        params: {
            id: id
        }
    }).then(res => {
        if (res.data.code == 200) {
            let d = res.data.result

            ruleForm.id = d.id
            ruleForm.schemeName = d.schemeName
            ruleForm.assessmentObject = d.assessmentObject
            ruleForm.assessmentState = d.assessmentState
            ruleForm.assessmentCycle = d.assessmentCycle
            ruleForm.assessmentType = d.assessmentType
            ruleForm.objectiveEvaluationWeight = d.objectiveEvaluationWeight
            ruleForm.subjectiveEvaluationWeight = d.subjectiveEvaluationWeight
        }
    })
}

//修改考核方案
const update = () => {
    axios.put('http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/UpdateAssessmentScheme', ruleForm).then(res => {
        if (res.data.code == 200) {
            ElMessage({
                message: '修改成功',
                type: 'success',
            })
            router.go(0)
            dialogVisible6.value = false
        }
        else {
            ElMessage({
                message: '修改失败',
                type: 'error',
            })
        }
    })
}


//客观指标考核
const SelectObjective = () => {
    if (Id.value == 0 || Id.value == null || Id.value == undefined) {
        //http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddAssessmentScheme
        axios.post('http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddAssessmentScheme', ruleForm).then(res => {
            if (res.data.code == 200) {
                Id.value = res.data.result
                dialogVisible3.value = true
            }
        })
    } else {
        dialogVisible3.value = true
    }
}
//主观指标考核
const Selectsubjective = () => {
    if (Id.value == 0 || Id.value == null || Id.value == undefined) {
        //http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddAssessmentScheme
        axios.post('http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddAssessmentScheme', ruleForm).then(res => {
            if (res.data.code == 200) {
                Id.value = res.data.result
                dialogVisible4.value = true
            }
        })
    } else {
        dialogVisible4.value = true
    }
}

const assessmentScheme = reactive({
    "id": "",
    "schemeName": "",
    "assessmentType": "",
    "assessmentCycle": "",
    "assessmentObject": "",
    "assessmentState": "",
    "objectiveEvaluationWeight": "",
    "subjectiveEvaluationWeight": "",
})
const ObjectiveAssessmentTable = ref([])
const SchemeAssessmentIndexTable = ref([])
const scoringRule = reactive({
    "indexWeight": "",
    "percent1": "",
    "percent2": "",
    "percent3": "",
    "percent4": "",
    "percent5": "",
    "percent6": "",
    "percent7": "",
    "percent8": "",
    "points1": "",
    "points2": "",
    "points3": "",
    "points4": "",
    "points5": ""
})
//我的解决方案
const getMySolution = () => {
    //考核方案

    setTimeout(() => {
        axios.get('http://47.95.178.186:8000/ExamineGetRout/api/AssessmentSchemeRead/GetAssessmentSchemeInfo', {
            params: {
                id: schemeName.value || 0
            }
        }).then(res => {
            if (res.data.code == 200) {
                let d = res.data.result

                assessmentScheme.schemeName = d.schemeName
                assessmentScheme.assessmentCycle = d.assessmentCycle
                assessmentScheme.assessmentType = d.assessmentType
                assessmentScheme.objectiveEvaluationWeight = d.objectiveEvaluationWeight
                assessmentScheme.subjectiveEvaluationWeight = d.subjectiveEvaluationWeight
            }
        })
    }, 500);

    //我的解决方案客观指标

    setTimeout(() => {
        axios.get('http://47.95.178.186:8000/ExamineGetRout/api/AssessmentSchemeRead/GetObjectiveAssessmentIndexList', {
            params: {
                id: schemeName.value || 0
            }
        }).then(res => {
            if (res.data.code == 200) {
                ObjectiveAssessmentTable.value = res.data.result
            }
        })
    }, 1500);

    //我的解决方案主观指标

    setTimeout(() => {
        axios.get('http://47.95.178.186:8000/ExamineGetRout/api/AssessmentSchemeRead/GetSchemeAssessmentIndexQuery', {
            params: {
                id: schemeName.value || 0
            }
        }).then(res => {
            if (res.data.code == 200) {
                SchemeAssessmentIndexTable.value = res.data.result
            }
        })
    }, 1000);

    //评分规则

    setTimeout(() => {
        axios.get('http://47.95.178.186:8000/ExamineGetRout/api/AssessmentSchemeRead/GetScoringRuleInfo', {
            params: {
                id: schemeName.value || 0
            }
        }).then(res => {
            if (res.data.code == 200) {
                let d = res.data.result

                scoringRule.indexWeight = d.indexWeight
                scoringRule.percent1 = d.percent1
                scoringRule.percent2 = d.percent2
                scoringRule.percent3 = d.percent3
                scoringRule.percent4 = d.percent4
                scoringRule.percent5 = d.percent5
                scoringRule.percent6 = d.percent6
                scoringRule.percent7 = d.percent7
                scoringRule.percent8 = d.percent8
                scoringRule.points1 = d.points1
                scoringRule.points2 = d.points2
                scoringRule.points3 = d.points3
                scoringRule.points4 = d.points4
                scoringRule.points5 = d.points5
            }
        })
    }, 2000);


}

//客观规则添加
const saveScoringRule = () => {
    selecttableData.value.forEach((item) => {
        item.schemeId = Id.value
    });
    scoringRuleData.schemeId = Id.value
    //http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddObjectiveAssessmentIndex
    let ObjectiveAssessmentIndexList = selecttableData.value
    axios.post('http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddObjectiveAssessmentIndex', { ObjectiveAssessmentIndexList }).then(res => {
        console.log(res.data.result)
    })
    //http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddScoringRule
    axios.post('http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddScoringRule', scoringRuleData).then(res => {
        if (res.data.result > 0) {
            ElMessage({
                message: '提交成功',
                type: 'success',
            })
            dialogVisible3.value = false
        }
    })
}

//主观添加
const saveSubjective = () => {
    selecttableData1.value.forEach((item) => {
        item.schemeId = Id.value
    });
    var count = selecttableData1.value.length
    if (count > 0) {
        var data1 = 1 / count * 100
        selecttableData1.value.forEach((item) => {
            item.indexWeight = data1.toFixed(2) + "%";
        });
    } else {
        selecttableData1.value.forEach((item) => {
            item.indexWeight = "0%";
        });
    }
    //http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddSchemeAssessmentIndex
    let SchemeAssessmentIndexList = selecttableData1.value
    axios.post('http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddSchemeAssessmentIndex', { SchemeAssessmentIndexList }).then(res => {
        if (res.data.code == 200) {
            ElMessage({
                message: '提交成功',
                type: 'success',
            })
            dialogVisible4.value = false
        }
    })
}

//客观指标表格数据
const tableData = ref([])
const getObjectiveAssessmentIndexList = () => {
    axios.get('http://47.95.178.186:8000/ExamineGetRout/api/AssessmentSchemeRead/GetAssessmentIndexList').then(res => {
        tableData.value = res.data.result
    })
}
//主观指标表格数据
const tableData1 = ref([])
const getAssessmentIndexQuery = () => {
    axios.get('http://47.95.178.186:8000/ExamineGetRout/api/AssessmentIndexRead/GetAssessmentIndexQuery').then(res => {
        tableData1.value = res.data.result
    })
}

//选择的客观指标
const selecttableData = ref<{
    "schemeId": number,
    "indexName": string,
    "indexDesc": string,
    "maximumFraction": number,
    "leastMinute": number
}[]>([])
const handleSelectionChange = (val: any) => {
    // 客观指标
    selecttableData.value = val
    var count = selecttableData.value.length

    if (count > 0) {
        var data = 1 / count * 100
        scoringRuleData.indexWeight = data.toFixed(2) + "%"
    } else {
        scoringRuleData.indexWeight = "0%"
    }

}
//选择的主观指标
const selecttableData1 = ref<{
    "schemeId": number,
    "indexType": string,
    "indexName": string,
    "indexDesc": string,
    "maximumFraction": number,
    "leastMinute": number,
    "initialScore": number,
    "indexWeight": string
}[]>([])
const handleSelectionChange1 = (val: any) => {

    // 主观指标
    selecttableData1.value = val
    var count = selecttableData1.value.length

    if (count > 0) {
        var data1 = 1 / count * 100
        selecttableData1.value.forEach((item) => {
            item.indexWeight = data1.toFixed(2) + "%";
        });
    } else {
        selecttableData1.value.forEach((item) => {
            item.indexWeight = "0%";
        });
    }
}

//选择考核对象
const Select = () => {
    dialogVisible2.value = true
    selectedNodeIds.value = []
}

//规则数据
const scoringRuleData = reactive({
    schemeId: 0,
    indexWeight: "",
    percent1: "",
    percent2: "",
    percent3: "",
    percent4: "",
    percent5: "",
    percent6: "",
    percent7: "",
    percent8: "",
    Points1: "",
    Points2: "",
    Points3: "",
    Points4: "",
    Points5: "",
})

//考核对象
const selectedNodeIds: Ref<string[]> = ref([]);

const handleNodeClick = (data: any) => {
    // 检查所选节点的 ID 是否已经存在于 selectedNodeIds 数组中
    if (!selectedNodeIds.value.includes(data.id)) {
        // 如果不存在，则将其添加到数组中
        selectedNodeIds.value.push(data.id);
        ruleForm.assessmentObject = selectedNodeIds.value.join(',');
    }
};

//删除考核对象
const deldata = () => {
    ruleForm.assessmentObject = ''
}

const defaultProps = {
    children: 'children',
    label: 'label',
    value: 'id',
};

interface Tree {
    id: string
    label: string
    children?: Tree[]
}

const data: Tree[] = [
    {
        id: "",
        label: '呼兰区',
        children: [
            {
                id: "李潇潇（呼兰街道网格长）",
                label: '呼兰街道',
                children: [],
            },
            {
                id: "陈圆圆（兰河街道网格长）",
                label: '兰河街道',
                children: [],
            },
            {
                id: "赵乾安（利民街道网格长）",
                label: '利民街道',
                children: [],
            },
            {
                id: "崔杰（康金街道网格长）",
                label: '康金街道',
                children: [],
            },
            {
                id: "宋凯（双井街道网格长）",
                label: '双井街道',
                children: [],
            },
        ],
    },
];


interface IschemeNameList {
    id: number,
    schemeName: string
}

//考核方案名称条件查询(非常重要)
const schemeName = ref('')

//考核方案管理的方案名称
const schemeNameList = ref<IschemeNameList[]>([])
const getschemeNameList = () => {
    //http://localhost:5171
    axios.get('http://47.95.178.186:8000/ExamineGetRout/api/AssessmentSchemeRead/GetSchemeNameDto').then(res => {
        schemeNameList.value = res.data.result
    })
}


//方案数据
const ruleForm = reactive({
    "id": 0,
    "schemeName": "",
    "assessmentType": "",
    "assessmentCycle": "",
    "assessmentObject": "",
    "assessmentState": "",
    "objectiveEvaluationWeight": "",
    "subjectiveEvaluationWeight": "",
})

//验证
const rules = reactive<FormRules>({
    schemeName: [
        {
            required: true,
            message: '请输入方案名称',
            trigger: 'change',
        },
    ],
    assessmentType: [
        {
            required: true,
            message: '请选择考核类型',
            trigger: 'change',
        },
    ],
    assessmentCycle: [
        { required: true, message: '请输入考核周期', trigger: 'blur' },
    ],
    assessmentObject: [
        {
            required: true,
            message: '请选择考核对象',
            trigger: 'change',
        },
    ],
    objectiveEvaluationWeight: [
        {
            required: true,
            message: '请输入客观评价权重',
            trigger: 'change',
        },
    ],
    subjectiveEvaluationWeight: [
        {
            required: true,
            message: '请输入主观评价权重',
            trigger: 'change',
        },
    ],
})

//添加考核方案
const submitForm = async (formEl: FormInstance | undefined, fing: any) => {
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            if (fing == 1) {
                ruleForm.assessmentState = "未提交"
                if (Id.value == 0 || Id.value == null || Id.value == undefined) {
                    axios.post('http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddAssessmentScheme', ruleForm).then(res => {
                        if (res.data.code == 200) {
                            ElMessage({
                                message: '保存成功',
                                type: 'success',
                            })
                            router.go(0)
                            dialogVisible.value = false
                        } else if (res.data.code == 202) {
                            ElMessage({
                                message: '方案名称已存在',
                                type: 'error',
                            })
                        } else {
                            ElMessage({
                                message: '提交失败',
                                type: 'error',
                            })
                        }
                    })
                } else {
                    ruleForm.id = Id.value
                    axios.put('http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/UpdateAssessmentScheme', ruleForm).then(res => {
                        if (res.data.code == 200) {
                            ElMessage({
                                message: '保存成功',
                                type: 'success',
                            })
                            router.go(0)
                            dialogVisible.value = false
                        }
                        else {
                            ElMessage({
                                message: '提交失败',
                                type: 'error',
                            })
                        }
                    })
                }
            } else {
                ruleForm.assessmentState = "未开始"
                if (Id.value == 0 || Id.value == null || Id.value == undefined) {
                    axios.post('http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/AddAssessmentScheme', ruleForm).then(res => {
                        if (res.data.code == 200) {
                            ElMessage({
                                message: '提交成功',
                                type: 'success',
                            })
                            router.go(0)
                            dialogVisible.value = false

                        } else if (res.data.code == 202) {
                            ElMessage({
                                message: '方案名称已存在',
                                type: 'error',
                            })
                        } else {
                            ElMessage({
                                message: '提交失败',
                                type: 'error',
                            })
                        }
                    })
                } else {
                    ruleForm.id = Id.value
                    axios.put('http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/UpdateAssessmentScheme', ruleForm).then(res => {
                        if (res.data.code == 200) {
                            ElMessage({
                                message: '提交成功',
                                type: 'success',
                            })
                            router.go(0)
                            dialogVisible.value = false
                        }
                        else {
                            ElMessage({
                                message: '提交失败',
                                type: 'error',
                            })
                        }
                    })
                }
            }
        }
    })
}

const resetForm = (formEl: FormInstance | undefined) => {
    if (!formEl) return
    formEl.resetFields()
}

//方案管理查询条件
const serchData = reactive({
    assessmentType: "",
    schemeName: "",
})

//方案管理分页数据
const page = reactive({
    pageIndex: 1,
    pageSize: 15,
    totalCount: 0,
    pageCount: 0,
})

const handleSizeChange = (val: number) => {
    page.pageIndex = 1
    page.pageSize = val
    getAssessmentSchemeList()
}

const handleCurrentChange = (val: number) => {
    page.pageIndex = val
    getAssessmentSchemeList()
}

//考核方案数据显示
const assessmentSchemeList = ref([])
const getAssessmentSchemeList = () => {
    axios.get('http://47.95.178.186:8000/ExamineGetRout/api/AssessmentSchemeRead/GetAssessmentSchemeList', {
        params: {
            pageIndex: page.pageIndex,
            pageSize: page.pageSize,
            assessmentType: serchData.assessmentType,
            schemeName: serchData.schemeName,
            assessmentObject: "" || null,
        }
    }).then(res => {
        if (res.data.code == 200) {
            assessmentSchemeList.value = res.data.result.data
            page.totalCount = res.data.result.totalCount
            page.pageCount = res.data.result.pageCount
        }
    })
}

//序号
const indexMethod = (index: number) => {
    return index += (page.pageSize) * (page.pageIndex - 1) + 1;
}

//考核方案删除
const deleteAssessmentScheme = (id: number) => {
    ElMessageBox.confirm(
        '确定要删除吗?',
        '提示',
        {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
        .then(() => {
            axios.delete('http://47.95.178.186:8000/ExamineSetRout/api/AssessmentScheme/RemoveAssessmentScheme', {
                params: {
                    id: id
                }
            }).then(res => {
                if (res.data.code == 200) {
                    ElMessage({
                        message: '删除成功',
                        type: 'success',
                    })
                    getAssessmentSchemeList()
                    getschemeNameList()
                }
                else {
                    ElMessage({
                        message: '删除失败',
                        type: 'error',
                    })
                }
            })
        })
        .catch(() => {
        })
}

//钩子函数
onMounted(() => {
    getObjectiveAssessmentIndexList()
    setTimeout(() => {
        getAssessmentIndexQuery()
    }, 200);
    setTimeout(() => {
        getAssessmentSchemeList()
    }, 400);
    setTimeout(() => {
        getschemeNameList()
    }, 600)
    setTimeout(() => {
        getMySolution()
    }, 2000);
})
</script>

<style>
/* 样式表头的第一行 */
.el-table thead>tr:first-child th {
    background-color: #10bdd7;
    color: white;
    /* 设置背景颜色 */
}
</style>